package com.micro.school.h5.controller;

import com.micro.school.common.core.context.SecurityContextHolder;
import com.micro.school.common.core.domain.R;
import com.micro.school.common.core.web.domain.AjaxResult;
import com.micro.school.system.api.RemoteEduService;
import com.micro.school.system.api.RemoteOrderService;
import com.micro.school.system.api.RemoteUserService;
import com.micro.school.system.api.domain.StudentInfos;
import com.micro.school.system.api.domain.vo.PayStudentFeeItemVos;
import com.micro.school.system.api.domain.vo.PayStudentFeeVos;
import com.micro.school.system.api.domain.vo.SchoolFeeYearVos;
import com.micro.school.system.api.domain.vo.StudentInfoVos;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/studentPay")
public class StudentH5PayController {

    @Resource
    private RemoteUserService remoteUserService;

    @Resource
    private RemoteOrderService remoteOrderService;

    @Resource
    private RemoteEduService remoteEduService;

    /**
     * 展示学生信息
     * @param studentInfoVos
     * @return
     */
    @PostMapping("/showStudent")
    public AjaxResult showStudent(@RequestBody StudentInfoVos studentInfoVos) {
        R<StudentInfos> studentInfosR = remoteUserService.queryStudent(studentInfoVos);
        StudentInfos data = studentInfosR.getData();
        return AjaxResult.success(data);
    }


    /**
     * 展示收费学年
     * @param
     * @return
     */
    @GetMapping("/showAllFeeYear")
    public AjaxResult showAllFeeYear() {
        SchoolFeeYearVos schoolFeeYearVos = new SchoolFeeYearVos();
        schoolFeeYearVos.setTenantId(Long.valueOf(SecurityContextHolder.getUserTenantId()));
        schoolFeeYearVos.setStatus("1");
        schoolFeeYearVos.setIsCloseChannel("1");
        schoolFeeYearVos.setDeleteFlag("0");
        R<List<SchoolFeeYearVos>> schoolFeeYearVosR = remoteEduService.checkFeeYear(schoolFeeYearVos);
        List<SchoolFeeYearVos> data = schoolFeeYearVosR.getData();
        return AjaxResult.success(data);
    }


    /**
     * 展示该生账单信息
     * @param
     * @return
     */
    @PostMapping("/showStudentOrder")
    public AjaxResult showStudentOrder(@RequestBody PayStudentFeeVos payStudentFeeVos) {
        R<PayStudentFeeVos> payStudentFeeVosR = remoteOrderService.queryStudentFee(payStudentFeeVos);
        if ( payStudentFeeVosR.getData() != null){
            return AjaxResult.success("查询成功",payStudentFeeVosR.getData());
        }else{
            PayStudentFeeVos data = new PayStudentFeeVos();
            return AjaxResult.success("查询成功",data);
        }


    }

    /**
     * 展示缴费模块
     * @param
     * @return
     */
    @PostMapping("/showStudentOrderDetail")
    public AjaxResult showStudentOrderDetail(@RequestBody PayStudentFeeVos payStudentFeeVos) {
        R<Map<String, Map<String, Object>>> payStudentFeeItemR = remoteOrderService.queryStudentFeeItem(payStudentFeeVos);
        Map<String, Map<String, Object>> data = payStudentFeeItemR.getData();
        return AjaxResult.success(data);
    }



    /**
     * 展示缴费模块详情
     * @param
     * @return
     */
    @PostMapping("/showDetails")
    public AjaxResult showDetails(@RequestBody PayStudentFeeVos payStudentFeeVos) {
        payStudentFeeVos.setPayStatus(10);
        R<List<PayStudentFeeItemVos>> payStudentFeeItemR = remoteOrderService.queryStudentFeeItemDetails(payStudentFeeVos);
        List<PayStudentFeeItemVos> data = payStudentFeeItemR.getData();
        return AjaxResult.success(data);
    }

    /**
     * 展示缴费模块详情
     * @param
     * @return
     */
    @PostMapping("/showDetailsPay")
    public AjaxResult showDetailsPay(@RequestBody PayStudentFeeVos payStudentFeeVos) {
        payStudentFeeVos.setPayStatus(20);
        R<List<PayStudentFeeItemVos>> payStudentFeeItemR = remoteOrderService.queryStudentFeeItemDetails(payStudentFeeVos);
        List<PayStudentFeeItemVos> data = payStudentFeeItemR.getData();
        return AjaxResult.success(data);
    }






}
